package org.x4444;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public abstract class AbsAggReducer extends Reducer<Text, IntWritable, Text, IntWritable> {

	Text k = new Text();
	IntWritable v = new IntWritable();

	@Override
	protected void reduce(Text key, Iterable<IntWritable> value, Context ctx)
			throws IOException, InterruptedException {

		int cell = 0;
		for (IntWritable val : value) {
			int vv = val.get();
			cell = operator(cell, vv);
		}

		v.set(cell);
		k.set(key.toString());
		ctx.write(k, v);
	}

	protected abstract int operator(int v1, int v2);
}
